package com.pospi.pospihold.ui.my_ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.TextView;

import com.pospi.pospihold.App;
import com.pospi.pospihold.R;
import com.pospi.pospihold.ui.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ChangePwdActivity extends BaseActivity {

    @Bind(R.id.tv_job_number)
    TextView tvJobNumber;
    @Bind(R.id.input_old_pwd)
    TextView inputOldPwd;
    @Bind(R.id.input_new_pwd1)
    TextView inputNewPwd1;
    @Bind(R.id.input_new_pwd2)
    TextView inputNewPwd2;
    @Bind(R.id.changeLoginPwdSure_btn)
    Button changeLoginPwdSureBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentLayout(R.layout.activity_change_pwd);
        setTitle("修改密码");
        ButterKnife.bind(this);

        tvJobNumber.setText(String.format("工号：%s", App.getCashierMsgDto().getNumber()));
    }

    @OnClick(R.id.changeLoginPwdSure_btn)
    public void onClick() {
        checkPwd();
    }

    /**
     * 判断原密码输入正确，新密码输入一致
     */
    private void checkPwd() {

        //原密码输入文本
        String txt_oldPwd = inputOldPwd.getText().toString();
        //新密码输入文本1
        String txt_newPwd1 = inputNewPwd1.getText().toString();
        //新密码输入文本2
        String txt_newPwd2 = inputNewPwd2.getText().toString();
        //判断是否有空值
        if (!TextUtils.isEmpty(txt_oldPwd) && !TextUtils.isEmpty(txt_newPwd1) && !TextUtils.isEmpty(txt_newPwd2)) {
            if (txt_oldPwd.equals(App.getCashierMsgDto().getPwd())) {//判断原密码正确
                if (txt_newPwd1.equals(txt_newPwd2)) {//两次新密码输入一致
                    //请求服务器，修改密码
                    showToast("修改成功！");
                    finish();
                } else {//新密码输入不一致
                    showToast("新密码两次输入不一致！请重试");
                    inputNewPwd1.setText("");
                    inputNewPwd2.setText("");
                }
            } else {//原密码错误
                showToast("原密码输入错误！");
                inputOldPwd.setText("");
            }
        } else {//有空值，提示
            showToast("密码不能为空！");
        }
    }

}
